using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// DAL class which authenticates user accounts
/// </summary>
public class DALAuthentication
{
    /// <summary>
    /// Authenticate username and password
    /// </summary>
    /// <param name="username"></param>
    /// <param name="password"></param>
    /// <returns>true if username and password are valid, false otherwise</returns>
    public static bool Authenticate(string username, string password)
    {
        AuthAccount authAccount = DAL.GetDataItem<AuthAccount>(SQL.Authenticate, new string[] { "@UserName", "@Password" }, new object[] { username, password });
        return (authAccount.UserName != string.Empty);
    }

    /// <summary>
    /// Get the role of the username
    /// </summary>
    /// <param name="username"></param>
    /// <returns>if username not existed then return string.empty, else return the role string</returns>
    public static string GetAccountRole(string username)
    {
        AuthAccount authAccount = DAL.GetDataItem<AuthAccount>(SQL.GetAccountRole, new string[] { "@UserName" }, new object[] { username });
        return authAccount.Role;
    }
}
